﻿using System;
using System.Linq;

namespace ECommerce.Administration
{
	public partial class AdminLogin : AdminBasePage
	{
		protected void LoginForm_LoggedIn(object sender, EventArgs e)
		{
			var user = System.Web.Security.Membership.GetUser(LoginForm.UserName);
			user.LastLoginDate = DateTime.Now;
			System.Web.Security.Membership.UpdateUser(user);
		}

		protected void UserName_Load(object sender, EventArgs e)
		{
			var userName = sender as System.Web.UI.WebControls.TextBox;

			userName.Focus();
		}

		protected void LoginForm_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
		{
			e.Authenticated = System.Web.Security.Roles.GetRolesForUser(LoginForm.UserName).Contains("Administrator") && System.Web.Security.Membership.ValidateUser(LoginForm.UserName, LoginForm.Password);
		}
	}
}
